/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pchart.hpp - Chart base class definition.
//
// Author: Jim DeLisle
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGCHART_
#define _PEGCHART_

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
struct PegChartPoint
{
    PegPoint ScreenPoint;
    PEGLONG  DataX;
    PEGLONG  DataY;
    PegChartPoint* pNext;

    PegChartPoint()
    {
        pNext = NULL;
        DataX = 0;
        DataY = 0;
        ScreenPoint.Set(0, 0);
    }

    PegChartPoint(PEGLONG x, PEGLONG y, PegChartPoint* pNextPtr = NULL)
    {
        DataX = x;
        DataY = y;
        pNext = pNextPtr;
        ScreenPoint.Set(0, 0);
    }
};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegChart : public PegThing
{
    public:
        PegChart(const PegRect& rect, PEGLONG MinX = 0, PEGLONG MaxX = 0,
                 PEGLONG MinY = 0, PEGLONG MaxY = 0, PEGUINT MajorXScale = 0,
                 PEGUINT MajorYScale = 0);
        virtual ~PegChart() {}

        virtual void Draw(const PegRect &Invalid);

        PegRect GetChartRegion() const { return mChartRegion; }
        PEGULONG GetExStyle() const { return mExStyle; }
        PegFont* GetFont() const { return mpFont; }
        PEGLONG GetMinX() const { return mMinX; }
        PEGLONG GetMinY() const { return mMinY; }

        PEGUINT GetMajorTicSize() const { return mMajorTicSize; }
        PEGUINT GetMajorXScale() const { return mMajorXScale; }
        PEGUINT GetMajorYScale() const { return mMajorYScale; }
        PEGLONG GetMaxX() const { return mMaxX; }
        PEGLONG GetMaxY() const { return mMaxY; }

        PEGUINT GetMinorTicSize() const { return mMinorTicSize; }
        PEGUINT GetMinorXScale() const { return mMinorXScale; }
        PEGUINT GetMinorYScale() const { return mMinorYScale; }

        PEGUINT GetXLabelHeight() const { return mXLabelHeight; }
        PEGUINT GetXLabelScale() const { return mXLabelScale; }
        PEGUINT GetYLabelScale() const { return mYLabelScale; }
        PEGUINT GetYLabelWidth() const { return mYLabelWidth; }

        virtual void MapDataToPoint(PegChartPoint* pPoint);
        virtual void MapPointToData(PegChartPoint* pPoint);
        virtual PEGINT Message(const PegMessage& Mesg);
        virtual void ParentShift(PEGINT xOffset, PEGINT yOffset);
        virtual void RecalcLayout(PEGBOOL Redraw = TRUE);
        virtual void RecalcSize(const PegRect& NewRect, PEGBOOL Redraw = TRUE);

        void SetExStyle(PEGULONG Style)
        { 
            mExStyle = Style;
            RecalcLayout(FALSE);
        }

        void SetFont(PEGINT FontIndex)
        {
            mFont = FontIndex;
            mpFont = PegResourceManager::GetFont(FontIndex);
        }

        void SetMinX(PEGLONG Data) { mMinX = Data; }
        void SetMinY(PEGLONG Data) { mMinY = Data; }
        void SetMajorTicSize(PEGUINT Size)
        {
            mMajorTicSize = Size;
            RecalcLayout(FALSE);
        }
        void SetMajorXScale(PEGUINT Scale)
        {
            mMajorXScale = Scale;
            RecalcLayout(FALSE);
        }
        void SetMajorYScale(PEGUINT Scale)
        {
            mMajorYScale = Scale;
            RecalcLayout(FALSE);
        }
        void SetMaxX(PEGLONG Data) { mMaxX = Data; }
        void SetMaxY(PEGLONG Data) { mMaxY = Data; }
        void SetMinorXScale(PEGUINT Scale)
        {
            mMinorXScale = Scale;
            if (mMinorXScale > mMajorXScale)
            {
                RecalcLayout(FALSE);
            }
        }
        void SetMinorYScale(PEGUINT Scale)
        {
            mMinorYScale = Scale;
            if(mMinorYScale > mMajorYScale)
            {
                RecalcLayout(FALSE);
            }
        }
        void SetMinorTicSize(PEGUINT Size)
        {
            mMinorTicSize = Size;
            RecalcLayout(FALSE);
        }
        void SetXLabelHeight(PEGUINT wHeight)
        {
            mXLabelHeight = wHeight;
            RecalcLayout(FALSE);
        }
        void SetXLabelScale(PEGUINT Scale)
        {
            mXLabelScale = Scale;
            RecalcLayout(FALSE);
        }
        void SetYLabelScale(PEGUINT Scale)
        {
            mYLabelScale = Scale;
            RecalcLayout(FALSE);
        }
        void SetYLabelWidth(PEGUINT Width)
        {
            mYLabelWidth = Width;
            RecalcLayout(FALSE);
        }


    protected:
        virtual void DrawXGrid(const PegRect &Invalid);
        virtual void DrawXLabels(const PegRect &Invalid);
        virtual void DrawXTics(const PegRect &Invalid);
        virtual void DrawYGrid(const PegRect &Invalid);
        virtual void DrawYLabels(const PegRect &Invalid);
        virtual void DrawYTics(const PegRect &Invalid);

        PegRect mChartRegion;

        PegFont* mpFont;

        PEGLONG mMaxX;
        PEGLONG mMaxY;
        PEGLONG mMinX;
        PEGLONG mMinY;

        PEGUINT mMajorXScale;
        PEGUINT mMinorXScale;
        PEGUINT mMajorYScale;
        PEGUINT mMinorYScale;
        PEGUINT mMajorTicSize;
        PEGUINT mMinorTicSize;
        PEGUINT mXLabelScale;
        PEGUINT mYLabelScale;
        PEGUINT mXLabelHeight;
        PEGUINT mYLabelWidth;

        PEGINT mFont;

        PEGULONG mExStyle;

};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegChartLine
{
    public:
        PegChartLine(PegChart* pParent, PEGUBYTE ID, PEGCOLOR Color);
        virtual ~PegChartLine();


        PegChartPoint* AddPoint(PEGLONG X, PEGLONG Y);
        virtual void Draw(const PegRect &Invalid);

        PEGCOLOR GetFillColor() const { return mBkgColor.LineColor; }
        PegChartPoint* GetFirstPoint() const { return mpPoints; }
        PEGUBYTE GetID() const { return mID; }
        PEGCOLOR GetLineColor() const { return mColor.LineColor; }
        PegChartLine* GetNext() const { return mpNext; }
        PegChartPoint* InsertPoint(PegChartPoint* pPreviousPoint, 
                                   PEGLONG X, PEGLONG Y);

        void MapDataToPoint(PegChartPoint* pPoint) 
        { 
            mpParent->MapDataToPoint(pPoint);
        }

        void RecalcLine();
        PegChartPoint* RemovePoint(PegChartPoint* pPoint);
        void ResetLine();

        void SetFillColor(PEGCOLOR Color) 
        { 
            mBkgColor.LineColor = Color;
        }
        void SetLineColor(PEGCOLOR Color) { mColor.LineColor = Color; }
        void SetNext(PegChartLine* pLine) { mpNext = pLine; }


    protected:
        PegChartLine*   mpNext;
        PegChartPoint*  mpPoints;
        PegChart*       mpParent;
        PegBrush        mColor;
        PegBrush        mBkgColor;
        PEGUBYTE        mID;
};

#endif // _PEGCHART_


